package BaseObject;

public class Itinerary3 extends Itinerary{

	public Itinerary3(Client c1, Client c2) {
		super(c1,c2);
	}

	public boolean computeItinerary(double base)
	{
		//Compute the minimum length for client's rides

		this.length = this.clientItinerary.get(0).getPosition().distance(this.clientItinerary.get(0).getDestination());

		this.length += this.clientItinerary.get(1).getPosition().distance(this.clientItinerary.get(1).getDestination());

		double probaC2 = Tools.N(15.0,5.0, Motor.currentTime - this.clientItinerary.get(1).getAppearingTime() + ( base + this.length + this.clientItinerary.get(0).getDestination().distance(this.clientItinerary.get(1).getPosition()) ) * Motor.stepTime );;

		this.length -= this.clientItinerary.get(0).getDestination().distance(this.clientItinerary.get(1).getPosition());

		this.length = this.length - base;

		double probaC1 = Tools.N(15.0,5.0, Motor.currentTime - this.clientItinerary.get(0).getAppearingTime() + base * Motor.stepTime );

		probaC1 = 1 - probaC1;
		probaC2 = 1 - probaC2;
		
		double probaC1ANDC2 = probaC1 *probaC2 ;
		double probaC2C1 = probaC1ANDC2 / probaC1;
		this.probability = probaC2C1;

		return true;
	}

	public void moveThisTaxi(Taxi t)
	{
		boolean change=false;

		if(t.getTekenClientList().size()==1 && t.getItinerary() != null)
		{
			//S'il a le premier client
			Client c = t.getItinerary().clientItinerary.get(0);
			if(t.getTekenClientList().get(0).equals(c))
			{
				
				change = t.deplacerTaxi(c.getDestination());
				System.out.println("bouge ; "+ change);
			
				if(change) 	// Si l'on arrive sur le client
				{
					Motor.clientsTaken.remove(c);
					t.getTekenClientList().remove(c);
					
				}
			}
			else
			{
				t.getTekenClientList().clear();
				t.setItinerary(null);

			}
		}
	}
}


